package UILayer;

import java.util.ArrayList;
import java.util.Scanner;

import CtrLayer.VareCtr;
import ModelLayer.Vare;

public class VareUI {
	private VareCtr vCtr;
	
	public VareUI()
	{
		vCtr = new VareCtr();
	}
	
	/**
	 * Start Vare UI method.
	 * 
	 * */
	public void startVareUI()
	{
		boolean start = false;
		while(!start){
			Scanner input = new Scanner(System.in);
			System.out.println("1. Add Vare");
			System.out.println("2. Remove Vare");
			System.out.println("3. Find Vare");
			System.out.println("4. Create produkt gruppe");
			System.out.println("5. Remove produkt gruppe");
			System.out.println("6. Add Vare to Produktgruppe");
			System.out.println("7. List of all varer");
			
			
			int choice = input.nextInt();
			switch(choice){
				case 1:
					createVare();
					break;
				case 2:
					removeVare();
					break;
				case 3:
					findVare();
					break;
				case 4:
					createProduktGruppe();
					break;
				case 5:
					removeProduktGruppe();
					break;
				case 6:
					addVareToProduktGruppe();
					break;
				case 7:
					listAllVarer();
					break;
				default:
					System.out.println("Quitting VareUI!");
					start = true;
					break;
			}
		}
	}
	/**
	 * Add Vare
	 * @param int artikelNr, int vaegt, float pris, String vareGruppe, String placering, int antal
	 * */
	public void createVare()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter artikelNr.: ");
		int aN = input.nextInt();
		System.out.println("Enter weight: ");
		int vg = input.nextInt();
		System.out.println("Enter price: ");
		float pris = input.nextFloat();
		System.out.println("Enter vareGruppe: ");
		String vareG = input.next();
		System.out.println("Enter placering: ");
		String pla = input.next();
		System.out.println("Enter amount: ");
		int antal = input.nextInt();
		
		vCtr.createVare(aN, vg, pris, vareG, pla, antal);
		System.out.println("Vare added to system!");
	}
	
	/**
	 * Remove vare from system.
	 * @param int artikelNr
	 * */
	public void removeVare()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter artikelNr.: ");
		int aN = input.nextInt();
		
		vCtr.removeVare(aN);	
	}
	
	/**
	 * Find vare
	 * @param int artikelNr.
	 * */
	public void findVare()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter artikelNr.: ");
		int aN = input.nextInt();
		Vare v = vCtr.findVare(aN);
		System.out.println("Artikel Nr.: " + v.getArtikelNr());
		System.out.println("Vaegt: " + v.getVaegt());
		System.out.println("Pris: " + v.getPris());
		System.out.println("Vare Gruppe: " + v.getVareGruppe());
		System.out.println("Placering: " + v.getPlacering());
		System.out.println("Antal: " + v.getAntal());
	}
	/**
	 * Create Produkt gruppe.
	 * @param String beskrivelse, int gruppeNr
	 * */
	public void createProduktGruppe()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter beskrivelse: ");
		String bs = input.next();
		System.out.println("Enter gruppeNr: ");
		int gN = input.nextInt();
		
		vCtr.createProduktGruppe(bs, gN);		
	}
	/**
	 * Remove produkt gruppe.
	 * @param int gruppeNr
	 * */
	public void removeProduktGruppe()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter gruppe Nr.: ");
		int gN = input.nextInt();
		
		vCtr.removeProduktGruppe(gN);
	}

	/**
	 * Add vare to produktgruppe
	 * @param int gruppeNr, int artikelNr
	 * */
	public void addVareToProduktGruppe()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter gruppe nr: ");
		int gN = input.nextInt();
		System.out.println("Enter artikelNr: ");
		int aN = input.nextInt();
		
		vCtr.addVareToProduktGruppe(gN, aN);
	}
	/**
	 * List all varer
	 * */
	public void listAllVarer()
	{
		ArrayList<Vare> vList = vCtr.listOfAllVarer();
		for(Vare x: vList){
			System.out.println("ArtikelNr: " + x.getArtikelNr());
			System.out.println("Pris: " + x.getPris());
			System.out.println("Placering: " + x.getPlacering());
			System.out.println("Antal: " + x.getAntal());
			System.out.println("--------------------------------------------");
		}
	}
}
